package com.cswangdao.controller.admin;

import com.cswangdao.domain.dto.IssuePageDTO;
import com.cswangdao.domain.model.MarketIssue;
import com.cswangdao.result.PageResult;
import com.cswangdao.result.Result;
import com.cswangdao.service.IssueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/admin/issue")
@RestController
@Slf4j
public class AdminIssueController {

    @Autowired
    IssueService issueService;

    @GetMapping("/list")
    public Result<PageResult<MarketIssue>> list(IssuePageDTO pageDTO)  {
        log.info("问题列表查询：{}", pageDTO);
        PageResult<MarketIssue> pageResult = issueService.pageQueryInfo(pageDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/update")
    public Result update(@RequestBody MarketIssue issue){
        log.info("问题更新：{}", issue);
        issueService.updateById(issue);
        return Result.success();
    }

    @PostMapping("/create")
    public Result<MarketIssue> create(@RequestBody MarketIssue issue){
        log.info("问题创建：{}", issue);
        MarketIssue marketIssue = issueService.addIssue(issue);
        return Result.success(marketIssue);
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody MarketIssue issue) {
        log.info("问题删除：{}", issue);
        issueService.deleteById(issue.getId());
        return Result.success();
    }

}

